package com.wwj.core.pay.weixin.refund;

//import com.thoughtworks.xstream.annotations.XStreamAlias;

import com.wwj.core.pay.weixin.Configure;
import com.thoughtworks.xstream.annotations.XStreamAlias;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

@XStreamAlias("xml")
public class RefundReqData {
    /**
     * 公众账号id，必须的
     */
    private String appid = Configure.appID;
    /**
     * 商户号，必须的
     */
    private String mch_id = Configure.mchID;
    /**
     * 设备号，非必须
     */
    private String device_info;
    /**
     * 随机字符串，必须的
     */
    private String nonce_str;
    /**
     * 签名
     */
    private String sign;
    /**
     * 签名类型，非必须
     */
    private String sign_type;
    /**
     * 微信订单号，必须的（跟商户订单号二选一）
     */
    private String transaction_id;
    /**
     * 商户订单号，必须的（跟微信订单号二选一）
     */
    private String out_trade_no;
    /**
     * 商户退款单号，必须的
     */
    private String out_refund_no;
    /**
     * 订单金额(必须的),订单总金额，单位为分，只能为整数
     */
    private int total_fee;
    /**
     * 退款金额（必须的）,退款总金额，订单总金额，单位为分，只能为整数
     */
    private int refund_fee;
    /**
     * 货币种类，非必须。默认CNY（人民币）
     */
    private String refund_fee_type;
    /**
     * 操作员，默认商户号
     */
    private String op_user_id = Configure.mchID;
    /**
     * 退款资金来源,仅针对老资金流商户使用
     REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款（默认使用未结算资金退款）
     REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款
     */
    private String refund_account;

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getMch_id() {
        return mch_id;
    }

    public void setMch_id(String mch_id) {
        this.mch_id = mch_id;
    }

    public String getDevice_info() {
        return device_info;
    }

    public void setDevice_info(String device_info) {
        this.device_info = device_info;
    }

    public String getNonce_str() {
        return nonce_str;
    }

    public void setNonce_str(String nonce_str) {
        this.nonce_str = nonce_str;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getSign_type() {
        return sign_type;
    }

    public void setSign_type(String sign_type) {
        this.sign_type = sign_type;
    }

    public String getTransaction_id() {
        return transaction_id;
    }

    public void setTransaction_id(String transaction_id) {
        this.transaction_id = transaction_id;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }

    public String getOut_refund_no() {
        return out_refund_no;
    }

    public void setOut_refund_no(String out_refund_no) {
        this.out_refund_no = out_refund_no;
    }

    public int getTotal_fee() {
        return total_fee;
    }

    public void setTotal_fee(int total_fee) {
        this.total_fee = total_fee;
    }

    public int getRefund_fee() {
        return refund_fee;
    }

    public void setRefund_fee(int refund_fee) {
        this.refund_fee = refund_fee;
    }

    public String getRefund_fee_type() {
        return refund_fee_type;
    }

    public void setRefund_fee_type(String refund_fee_type) {
        this.refund_fee_type = refund_fee_type;
    }

    public String getOp_user_id() {
        return op_user_id;
    }

    public void setOp_user_id(String op_user_id) {
        this.op_user_id = op_user_id;
    }

    public String getRefund_account() {
        return refund_account;
    }

    public void setRefund_account(String refund_account) {
        this.refund_account = refund_account;
    }

    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<String, Object>();
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            Object obj;
            try {
                obj = field.get(this);
                if (obj != null) {
                    map.put(field.getName(), obj);
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return map;
    }

    public RefundReqData build(String nonce_str,String sign,String transaction_id,String out_trade_no,String out_refund_no,int total_fee,int refund_fee){
        if(null == nonce_str || "".equals(nonce_str))
            throw new IllegalArgumentException("随机字符串不能为空");
        if(null == sign || "".equals(sign))
            throw new IllegalArgumentException("签名不能为空");
        if((null == transaction_id || "".equals(transaction_id)) &&(null == out_trade_no || "".equals(out_trade_no)))
            throw new IllegalArgumentException("");

        this.nonce_str = nonce_str;
        this.sign = sign;
        this.transaction_id = transaction_id;
        this.out_trade_no = out_trade_no;
        this.out_refund_no = out_refund_no;
        this.total_fee = total_fee;
        this.refund_fee = refund_fee;
        return this;
    }

}
